package com.xmhmyh.generalframework.framework.security;

import com.xmhmyh.generalframework.project.sys.entity.User;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @Author: 于丁
 * @DateTime: 2020/7/20 7:54 下午
 */
public class LoginUser implements UserDetails, Serializable {

    private static final long serialVersionUID = -5328714075530957511L;

    public LoginUser() {
    }
    /**
     * 用户信息
     */
    private User user;
    /**
     * 令牌密钥
     */
    private String token;
    /**
     * 登录时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expireTime;

    private List<UserPermissionsOrRole> userPermissionsOrRoles;

    private Map<Long, String> menuIdsMap;

    public Map<Long, String> getMenuIdsMap() {
        return menuIdsMap;
    }

    public void setMenuIdsMap(Map<Long, String> menuIdsMap) {
        this.menuIdsMap = menuIdsMap;
    }


    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }


    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public Long getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(Long loginTime) {
        this.loginTime = loginTime;
    }

    public Long getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Long expireTime) {
        this.expireTime = expireTime;
    }

    public List<UserPermissionsOrRole> getUserPermissionsOrRoles() {
        return userPermissionsOrRoles;
    }

    public LoginUser(User user) {
        this.user = user;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return userPermissionsOrRoles;
    }

    public void setUserPermissionsOrRoles(List<UserPermissionsOrRole> userPermissionsOrRoles) {
        this.userPermissionsOrRoles = userPermissionsOrRoles;
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }


}
